package com.ss.android.newmedia.a;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ConsoleMessage;
import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.b.WebViewPauseResumeCompat;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.app.AbsFragment;
import com.ss.android.common.app.WebViewTweaker;
import com.ss.android.common.app.permission.PermissionsManager;
import com.ss.android.common.app.permission.PermissionsResultAction;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.download.DownloadAdapterProxy;
import com.ss.android.common.download.DownloadInfoChangeListener;
import com.ss.android.common.download.DownloadShortInfo;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.ui.view.FullscreenVideoFrame;
import com.ss.android.common.util.LoadUrlUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.loader.LargeImageCtxRef;
import com.ss.android.image.loader.LargeImageLoader;
import com.ss.android.image.n;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.model.BaseArticle;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.activity.FragmentActivity;
import com.ss.android.newmedia.e.WapStatHelper;
import com.ss.android.newmedia.e.JsObject;
import com.ss.android.newmedia.util.AppUtil;
import com.ss.android.newmedia.webview.BaseWebChromeClient;
import com.ss.android.newmedia.webview.DelegateWebViewClient;
import com.ss.android.newmedia.webview.SSWebSettings;
import com.ss.android.newmedia.webview.SSWebView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

public class BrowserFragment extends AbsFragment implements Callback, LargeImageCtxRef, com.ss.android.newmedia.activity.browser.e, JsObject.ContextDataProvider {
    public final class e$a implements DownloadInfoChangeListener {
        public final BrowserFragment b;
        long a;

        protected e$a(BrowserFragment arg1) {
            this.b = arg1;
        }

        public final void setDownloadId(long id) {
            this.a = id;
        }

        public final void onDownloadProgressChanged(DownloadShortInfo arg10, int arg11, long arg12, long arg14, long arg16) {
            this.b.mHandler.post(new o(this, arg10, arg11, arg12, arg14));
        }
    }

    final class CustomWebChromeClient extends BaseWebChromeClient {

        CustomWebChromeClient(BrowserFragment browserFragment) {
            super(browserFragment);
        }

        public final void onConsoleMessage(String message, int lineNumber, String sourceID) {
            if (Logger.debug()) {
                Logger.d("BrowserFragment", message + " -- line " + lineNumber);
            }

            try {
                if (mJsObject == null) {
                    return;
                }
                mJsObject.checkLogMsg(message);
            } catch (Exception exception) {
            }
        }

        public final boolean onConsoleMessage(ConsoleMessage arg2) {
            return super.onConsoleMessage(arg2);
        }

        public final void onGeolocationPermissionsHidePrompt() {
            if (mJsObject != null) {
                mJsObject.onGeolocationPermissionsHidePrompt();
            }
        }

        public final void onGeolocationPermissionsShowPrompt(String arg2, GeolocationPermissions.Callback arg3) {
            if (mJsObject != null) {
                mJsObject.onGeolocationPermissionsShowPrompt(arg2, arg3);
            }
        }

        public final void onHideCustomView() {
            WebChromeClient.CustomViewCallback v2 = null;
            if (BrowserFragment.this.mCustomView == null) {
                mCustomViewCallback = v2;
            } else {
                if (BrowserFragment.this.getActivity() != null && ((BrowserFragment.this.getActivity() instanceof FragmentActivity))) {
                    ((FragmentActivity) BrowserFragment.this.getActivity()).showTitleBar();
                }

                mFullscreenViewFrame.setVisibility(View.GONE);
                mFullscreenViewFrame.removeView(BrowserFragment.this.mCustomView);
                UIUtils.requestActivityOrientation(BrowserFragment.this.getActivity(), false);
                BrowserFragment.this.mCustomView = ((View) v2);
                mCustomViewCallback.onCustomViewHidden();
            }
        }

        public final void onProgressChanged(WebView arg4, int arg5) {
            BrowserFragment v0 = BrowserFragment.this;
            v0.F = true;
            if (v0.mSSHtmlProgressBar != null) {
                v0.mSSHtmlProgressBar.setProgress(arg5);
                v0.mHandler.removeCallbacks(v0.w);
                if (v0.mSSHtmlProgressBar.getVisibility() != View.VISIBLE) {
                    v0.mSSHtmlProgressBar.setVisibility(View.VISIBLE);
                }
            }

            if (arg5 >= 100) {
                BrowserFragment.this.o();
            }
        }

        public final void onReceivedTitle(WebView webView, String title) {
            super.onReceivedTitle(webView, title);
            if ((BrowserFragment.this.u) && BrowserFragment.this.getActivity() != null && !android.support.design.a.isTextEmpty(title)) {
                BrowserFragment.this.getActivity().setTitle(title);
            }
        }

        public final void onSelectionStart(WebView webView) {
        }

        public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
            if ((BrowserFragment.a(BrowserFragment.this)) && (BrowserFragment.this.z)) {
                if (BrowserFragment.this.mCustomView != null) {
                    customViewCallback.onCustomViewHidden();
                } else {
                    if (BrowserFragment.this.getActivity() != null && ((BrowserFragment.this.getActivity() instanceof FragmentActivity))) {
                        ((FragmentActivity) BrowserFragment.this.getActivity()).hideTitleBar();
                    }

                    BrowserFragment.this.mCustomViewCallback = customViewCallback;
                    BrowserFragment.this.mFullscreenViewFrame.addView(view);
                    BrowserFragment.this.mCustomView = view;
                    UIUtils.requestActivityOrientation(BrowserFragment.this.getActivity(), true);
                    BrowserFragment.this.mFullscreenViewFrame.setVisibility(View.VISIBLE);
                    BrowserFragment.this.mFullscreenViewFrame.requestFocus();
                }
            }
        }
    }

    final class CustomWebViewClient extends DelegateWebViewClient {
        private final String[] a;

        CustomWebViewClient(BrowserFragment browserFragment) {
            this.a = new String[]{"snssdk.com", "bytecdn.com", "pstatp.com", "toutiao.com", "bytecdn.cn"};
        }

        private boolean a(String arg9) {
            boolean v0 = false;
            if (!TextUtils.isEmpty(((CharSequence) arg9))) {
                String v3 = Uri.parse(arg9).getHost();
                if (!TextUtils.isEmpty(((CharSequence) v3))) {
                    String[] v4 = this.a;
                    int v2 = 0;
                    while (v2 < 5) {
                        String v5 = v4[v2];
                        if (v3.equals(v5)) {
                            v0 = true;
                        } else if (v3.endsWith("." + v5)) {
                            v0 = true;
                        } else {
                            ++v2;
                            continue;
                        }

                        return v0;
                    }
                }
            }

            return v0;
        }

        public final void doUpdateVisitedHistory(WebView arg5, String arg6, boolean arg7) {
            if (Logger.debug()) {
                Logger.v("BrowserFragment", "doUpdateVisitedHistory " + arg5.getUrl() + " " + arg6 + " " + arg7);
            }

            super.doUpdateVisitedHistory(arg5, arg6, arg7);
            BrowserFragment.this.E = true;
            p();
            if (BrowserFragment.this.H > 0) {
                BrowserFragment.this.K.c(arg5, arg6);
            }
        }

        public final void onLoadResource(WebView arg4, String arg5) {
            if ((Logger.debug()) && !TTUtils.isValidUrl(arg5)) {
                Logger.d("BrowserFragment", "onLoadResource " + arg5);
            }

            JsObject v0 = BrowserFragment.this.mJsObject;
            if (v0 != null) {
                try {
                    v0.parseMsgQueue(arg5);
                } catch (Exception v0_1) {
                }
            }
        }

        public final void onPageFinished(WebView arg5, String url) {
            if (Logger.debug()) {
                Logger.v("BrowserFragment", "onPageFinished " + url);
            }

            if (BrowserFragment.this.K != null) {
                BrowserFragment.this.K.onPageFinished(arg5, url);
            }

            if (BrowserFragment.this.Q != null) {
                BrowserFragment.this.Q.onPageFinished();
            }

            if (BrowserFragment.this.H > 0 && arg5 != null && BrowserFragment.this.mBaseAppData != null) {
                String v0 = SSWebSettings.buildAdJs(BrowserFragment.this.mBaseAppData.r(), BrowserFragment.this.H);
                if (!android.support.design.a.isTextEmpty(v0)) {
                    LoadUrlUtils.loadUrl(arg5, v0);
                }
            }

            BrowserFragment.this.mBaseAppData.ae();
            super.onPageFinished(arg5, url);
        }

        public final void onPageStarted(WebView webView, String url, Bitmap favicon) {
            super.onPageStarted(webView, url, favicon);
            if (Logger.debug()) {
                Logger.v("BrowserFragment", "onPageStarted " + url);
            }

            if (BrowserFragment.this.Q != null) {
                BrowserFragment.this.Q.onPageStarted();
            }

            if (BrowserFragment.this.K != null) {
                BrowserFragment.this.K.onPageStarted(webView, url, true, BrowserFragment.this.y);
            }
        }

        public final void onReceivedError(WebView webView, int errorCode, String description, String failingUrl) {
            super.onReceivedError(webView, errorCode, description, failingUrl);
            BrowserFragment.this.o();
            if (BrowserFragment.this.Q != null) {
                BrowserFragment.this.Q.onPageReceivedError();
            }

            if (BrowserFragment.this.K != null) {
                BrowserFragment.this.K.onReceivedError(errorCode);
            }
        }

        public final void onReceivedSslError(WebView arg5, final SslErrorHandler arg6, SslError arg7) {
            try {
                Logger.d("BrowserFragment", "onReceivedSslError: " + arg7.getUrl());
                try {
                    com.bytedance.article.common.a.g.a("sslErrorInfo", new JSONObject().putOpt("sslErrorInfo", arg7.toString()));
                } catch (JSONException v0_1) {
                }
                int v0_2 = BaseAppData.inst().cy;
                if (2 == v0_2) {
                    arg6.proceed();
                    return;
                }

                if (1 != v0_2) {
                } else if (!this.a(arg7.getUrl())) {
                } else {
                    arg6.proceed();
                    return;
                }
            } catch (Exception v0) {
                v0.printStackTrace();
            }

            try {
                AlertDialog v1 = new AlertDialog.Builder(BrowserFragment.this.getActivity()).create();
                String v0_3 = BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_error);
                switch (arg7.getPrimaryError()) {
                    case 0: {
                        v0_3 = BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_notyetvalid);
                        break;
                    }
                    case 1: {
                        v0_3 = BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_expired);
                        break;
                    }
                    case 2: {
                        v0_3 = BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_mismatched);
                        break;
                    }
                    case 3: {
                        v0_3 = BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_untrusted);
                        break;
                    }
                }

                v0_3 = v0_3 + BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_continue);
                v1.setTitle(com.ss.android.article.browser.R.string.ssl_warning);
                v1.setTitle(((CharSequence) v0_3));
                v1.setButton(-1, BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_ok), new DialogInterface.OnClickListener() {

                    public final void onClick(DialogInterface arg2, int arg3) {
                        arg6.proceed();
                    }
                });
                v1.setButton(-2, BrowserFragment.this.getString(com.ss.android.article.browser.R.string.ssl_cancel), new DialogInterface.OnClickListener() {

                    public final void onClick(DialogInterface arg2, int arg3) {
                        arg6.cancel();
                    }
                });
                v1.show();
            } catch (Exception v0) {
                if (arg6 == null) {
                    return;
                }

                arg6.proceed();
            }

            return;
        }

        @TargetApi(value = 21)
        public final WebResourceResponse shouldInterceptRequest(WebView arg2, WebResourceRequest arg3) {
            return super.shouldInterceptRequest(arg2, arg3);
        }

        public final WebResourceResponse shouldInterceptRequest(WebView arg2, String arg3) {
            return super.shouldInterceptRequest(arg2, arg3);
        }

        public final boolean shouldOverrideUrlLoading(WebView arg7, String arg8) {
            Uri v2;
            boolean v0 = false;
            if (Logger.debug()) {
                Logger.d("BrowserFragment", "shouldOverrideUrlLoading " + arg8);
            }

            if (TTUtils.isValidUrl(arg8)) {
                if (BrowserFragment.this.K == null) {
                    return v0;
                }

                BrowserFragment.this.K.b(arg7, arg8);
                return v0;
            }

            try {
                v2 = Uri.parse(arg8);
                String v3 = v2.getScheme().toLowerCase();
                if (TextUtils.isEmpty(((CharSequence) v3))) {
                    return v0;
                }

                if ("about".equals(v3)) {
                    return v0;
                }

                if (!"bytedance".equals(v3)) {
                    try {
                        label_67:
                        if ("http".equals(v3)) {
                            return v0;
                        }

                        if ("https".equals(v3)) {
                            return v0;
                        }

                        if (BrowserFragment.this.mBaseAppData.i(arg8)) {
                            return true;
                        }

                        if (("sslocal".equals(v3)) || ("localsdk".equals(v3))) {
                            arg8 = AdsAppBaseActivity.b(arg8);
                        }

                        if ((BrowserFragment.this.J) && !com.ss.android.article.base.feature.app.a.c.b(v3)) {
                            return true;
                        }
                        try {
                            AppUtil.b(BrowserFragment.this.getActivity(), arg8);
                        } catch (Exception v2_1) {
                            try {
                                Logger.w("TAG", "action view " + arg8 + " exception: " + v2_1);
                            } catch (Exception v1) {
                                Logger.w("TAG", "view url " + arg8 + " exception: " + v1);
                                return v0;
                            }
                        }

                        return true;
                    } catch (Exception v1) {
                        Logger.w("TAG", "view url " + arg8 + " exception: " + v1);
                        return v0;
                    }
                }

                if (BrowserFragment.this.mJsObject != null && (JsObject.canHandleUri(v2))) {
                    try {
                        BrowserFragment.this.mJsObject.handleUri(v2);
                    } catch (Exception v2_1) {
                        Logger.w("BrowserFragment", "TTAndroidObj handleUri exception: " + v2_1);
                        return true;
                    }
                    return true;
                }

                BrowserFragment.this.a(v2, arg7);
                return true;
            } catch (Exception v1) {
            }
            return true;

        }
    }

    public interface WebViewClientListener {
        void onPageFinished();

        void onPageStarted();

        void onPageReceivedError();
    }

    final class e$e extends AsyncTask {

        protected final Object doInBackground(Object[] arg4) {
            DownloadShortInfo downloadShortInfo;
            if (arg4 != null) {
                if (arg4.length > 0 && (TextUtils.isEmpty((String) arg4[0]))) {
                    return null;
                }

                if (BrowserFragment.this.mContext == null) {
                    return null;
                }

                downloadShortInfo = DownloadAdapterProxy.inst().queryDownloadInfo(mContext, (String) arg4[0]);
            } else {
                return null;
            }
            return downloadShortInfo;
        }

        protected final void onPostExecute(Object arg11) {
            String v0_1;
            super.onPostExecute(arg11);
            if (!this.isCancelled()) {
                try {
                    if (!BaseAppData.inst().allowInsideDownloadManager()) {
                    } else if (arg11 == null) {
                    } else if (((DownloadShortInfo) arg11).id > -1) {
                        if (!ToolUtils.isAppInstalled(BrowserFragment.this.mContext, BrowserFragment.this.I)
                                && (DownloadAdapterProxy.inst().isDownloadSuccessAndFileNotExist(BrowserFragment.this.mContext, ((DownloadShortInfo) arg11)))) {
                        } else {
                            if (arg11 != null) {
                                DownloadAdapterProxy.inst().registerDownloadListener(
                                        BrowserFragment.this.mContext,
                                        Long.valueOf(((DownloadShortInfo) arg11).id),
                                        BrowserFragment.this.o,
                                        BrowserFragment.this.r,
                                        BrowserFragment.this.L,
                                        BrowserFragment.this.s);
                            }

                            BrowserFragment.this.n = ((DownloadShortInfo) arg11);
                            BrowserFragment.this.mDownloadStatusTv.setTextColor(BrowserFragment.this.getResources().getColor(com.ss.android.article.browser.R.color.hp));
                            switch (((DownloadShortInfo) arg11).b) {
                                case 1:
                                case 2: {
                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_pause);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.VISIBLE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(0);
                                    break;
                                }
                                case 4: {
                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_resume);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.VISIBLE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(0);
                                    break;
                                }
                                case 8: {
                                    if (ToolUtils.isAppInstalled(BrowserFragment.this.mContext, BrowserFragment.this.I)) {
                                        v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_open);
                                        BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                                        BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dl);
                                        break;
                                    }

                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_install);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dn);
                                    BrowserFragment.this.mDownloadStatusTv.setTextColor(BrowserFragment.this.getResources().getColor(com.ss.android.article.browser.R.color.hl));
                                    break;
                                }
                                case 16: {
                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_restart);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dl);
                                    break;
                                }
                                case 32: {
                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download_open);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dl);
                                    MobAdClickCombiner.onAdEvent(BrowserFragment.this.mContext,
                                            BrowserFragment.this.M,
                                            "install_finish",
                                            BrowserFragment.this.H, 0,
                                            BrowserFragment.this.t,
                                            BrowserFragment.this.P);
                                    break;
                                }
                                default: {
                                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download);
                                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dl);
                                    break;
                                }
                            }

                            if (((DownloadShortInfo) arg11).c > 0) {
                                BrowserFragment.this.mDownloadProgressBar.setProgress(((int) (((DownloadShortInfo) arg11).d * 100 / ((DownloadShortInfo) arg11).c)));
                            } else {
                                BrowserFragment.this.mDownloadProgressBar.setProgress(0);
                            }

                            BrowserFragment.this.mDownloadStatusTv.setText(v0_1);
                            label_74:
                            if (BrowserFragment.this.n == null) {
                                return;
                            }

                            DownloadAdapterProxy.inst().registerDownloadListener(BrowserFragment.this.mContext,
                                    Long.valueOf(BrowserFragment.this.n.id),
                                    BrowserFragment.this.o,
                                    BrowserFragment.this.r,
                                    BrowserFragment.this.L,
                                    BrowserFragment.this.s);
                            return;
                        }
                    }
                    if (BrowserFragment.this.n != null) {
                        DownloadAdapterProxy.inst().unregisterDownloadListener(
                                BrowserFragment.this.mContext,
                                Long.valueOf(BrowserFragment.this.n.id),
                                BrowserFragment.this.o);
                    }

                    BrowserFragment.this.n = null;
                    v0_1 = BrowserFragment.this.getResources().getString(com.ss.android.article.browser.R.string.detail_download);
                    BrowserFragment.this.mDownloadProgressBar.setVisibility(View.GONE);
                    BrowserFragment.this.mDownloadStatusTv.setBackgroundResource(com.ss.android.article.browser.R.drawable.dl);
                    BrowserFragment.this.mDownloadStatusTv.setText(((CharSequence) v0_1));
                    if (BrowserFragment.this.n == null) {
                        return;
                    }
                    DownloadAdapterProxy.inst().registerDownloadListener(
                            BrowserFragment.this.mContext,
                            Long.valueOf(BrowserFragment.this.n.id),
                            BrowserFragment.this.o,
                            BrowserFragment.this.r,
                            BrowserFragment.this.L,
                            BrowserFragment.this.s);
                } catch (Exception v0) {
                    v0.printStackTrace();
                }
            }
        }
    }

    public boolean A;
    BaseAppData mBaseAppData;
    public JsObject mJsObject;
    boolean D;
    boolean E;
    public boolean F;
    CustomWebChromeClient G;
    long H;
    String I;
    boolean J;
    public WapStatHelper K;
    int L;
    String M;
    DialogListener N;
    public boolean O;
    int P;
    protected WebViewClientListener Q;
    private com.ss.android.image.n R;
    private TaskInfo S;
    private long T;
    private String U;
    private String V;
    private JSONObject W;
    private boolean X;
    private View mDownloadStatusBar;
    private e$e b = new e$e();
    private boolean c;
    private Resources d;
    private boolean e;
    private LargeImageLoader mLargeImageLoader;
    FullscreenVideoFrame mFullscreenViewFrame;
    View mCustomView;
    WebChromeClient.CustomViewCallback mCustomViewCallback;
    public WebView mWebview;
    ProgressBar mSSHtmlProgressBar;
    ProgressBar mDownloadProgressBar;
    TextView mDownloadStatusTv;
    DownloadShortInfo n;
    final e$a o;
    String p;
    String q;
    String r;
    String s;
    JSONObject t;
    boolean u;
    Handler mHandler;
    Runnable w;
    public Context mContext;
    public String y;
    boolean z;

    public BrowserFragment() {
        this.o = new e$a(this);
        this.t = null;
        this.u = false;
        this.z = true;
        this.c = false;
        this.A = false;
        this.D = false;
        this.E = false;
        this.F = false;
        this.e = false;
        this.H = 0;
        this.J = false;
        this.T = 0;
        this.O = true;
        this.P = 0;
    }

    static boolean a(BrowserFragment arg1) {
        return arg1.O;
    }

    public SSWebView getWebView(View arg2) {
        return arg2.findViewById(com.ss.android.article.browser.R.id.ss_webview);
    }

    public void initTTAndroidObject() {
        if (this.mJsObject == null) {
            this.mJsObject = this.mBaseAppData.createJsObject(this.mContext);
            this.mJsObject.setLargeImageContext(this);
            this.mJsObject.setWebView(this.mWebview);
            this.mJsObject.mJsDataProvider = this;
        }
    }

    public void a(Uri arg1, WebView arg2) {
    }

    public final void setOnPageLoadListener(WebViewClientListener arg1) {
        this.Q = arg1;
    }

    public final void queryContextData(String key, HashMap arg4) {
        if ("cid".equals(key)) {
            arg4.put(key, Long.valueOf(this.H));
        } else if ("log_extra".equals(key)) {
            arg4.put(key, this.s);
        }
    }

    public void a(String arg5, boolean arg6) {
        if (this.mWebview != null) {
            if (this.W == null || this.W.length() <= 0) {
                TTUtils.a(arg5, this.mWebview);
            } else {
                HashMap v0 = new HashMap();
                AppUtil.appendAdditionHttpHeaders(v0, null, this.W);
                TTUtils.webViewLoadUrl(arg5, this.mWebview, v0);
            }

            if (!arg6) {
                return;
            }

            this.mWebview.postDelayed(new com.ss.android.newmedia.a.n(this), 1000);
        }
    }

    public final void startThumbPreviewActivity(List arg7, int arg8) {
        if (arg7 != null && !arg7.isEmpty() && (this.isViewValid()) && (this.R == null || !this.R.isShowing())) {
            if (this.R == null) {
                this.S = new TaskInfo();
                BaseImageManager v3 = new BaseImageManager(this.mContext);
                this.R = new n(this.mContext, v3);
                this.mLargeImageLoader = new LargeImageLoader(this.mContext, this.S, v3, this.R, this.R);
                this.R.b = this.mLargeImageLoader;
            }

            this.R.a(arg7, arg8);
            this.R.show();
        }
    }

    public void f() {
    }

    public int getLayoutId() {
        return com.ss.android.article.browser.R.layout.bb;
    }

    public void tryRefreshTheme() {
        int v2 = com.ss.android.article.browser.R.color.fw;
        this.mWebview.setBackgroundColor(this.d.getColor(v2));
        this.A = com.ss.android.j.b.isNightModeToggled();
        if (this.c) {
            if (this.A) {
                this.mWebview.setBackgroundColor(this.d.getColor(com.ss.android.article.browser.R.color.fx));
            } else {
                this.mWebview.setBackgroundColor(this.d.getColor(v2));
            }
        }
    }

    public void handleMsg(Message message) {
        switch (message.what) {
            case 10011: {
                if (!this.isActive() && this.mWebview != null) {
                    try {
                        this.mWebview.getSettings().setBlockNetworkLoads(true);
                    } catch (Exception v0) {
                    }
                }
            }
        }

        return;
    }

    public final void l() {
        this.D = true;
    }

    public final void m() {
        if (this.F) {
            this.mWebview.stopLoading();
        } else {
            this.mWebview.reload();
        }
    }

    public final WebView n() {
        return this.mWebview;
    }

    public final void o() {
        this.mHandler.removeCallbacks(this.w);
        this.mHandler.postDelayed(this.w, 500);
    }

    public void onActivityCreated(Bundle arg15) {
        String v13;
        String v12;
        String v0_1;
        super.onActivityCreated(arg15);
        this.mHandler = new WeakHandler(((Callback) this));
        this.w = new l(this);
        this.mContext = this.getActivity();
        this.mBaseAppData = BaseAppData.inst();
        this.d = this.mContext.getResources();
        this.z = this.mBaseAppData.mAllowHtmlVideo;
        this.initTTAndroidObject();
        Bundle v4 = this.getArguments();
        String v3 = "";
        String v2 = null;
        String v10 = null;
        boolean v1 = false;
        boolean v0 = false;
        if (v4 != null) {
            v1 = v4.getBoolean("bundle_no_hw_acceleration", false);
            this.e = v4.getBoolean("bundle_enable_app_cache", false);
            v4.getString("key_words");
            v0_1 = v4.getString("bundle_url");
            if (v0_1 == null) {
                v0_1 = "";
            }

            v10 = v4.getString("webview_track_key");
            this.p = v4.getString("bundle_download_url");
            this.q = v4.getString("bundle_download_app_name");
            this.r = v4.getString("bundle_download_app_extra");
            this.s = v4.getString("bundle_download_app_log_extra");
            boolean v2_1 = v4.getBoolean("bundle_is_from_app_ad");
            this.c = v4.getBoolean("bundle_use_day_night", false);
            v3 = v4.getString("referer");
            this.H = v4.getLong("ad_id", 0);
            this.I = v4.getString("package_name");
            this.J = v4.getBoolean("bundle_forbid_jump", false);
            this.u = v4.getBoolean("bundle_user_webview_title", false);
            this.L = v4.getInt("bundle_app_ad_from", 0);
            this.U = v4.getString("gd_label");
            this.V = v4.getString("gd_ext_json");
            String v4_1 = v4.getString("wap_headers");
            try {
                if (!android.support.design.a.isTextEmpty(v4_1)) {
                    this.W = new JSONObject(v4_1);
                }
                v12 = v3;
                v13 = v0_1;
                v0 = v1;
                v1 = v2_1;
            } catch (JSONException v4_2) {
                v12 = v3;
                v13 = v0_1;
                v0 = v1;
                v1 = v2_1;
//                goto label_96;
            }
        } else {
            v12 = v2;
            v13 = v3;
        }

//        label_96:
        boolean v11 = !v0 ? this.mBaseAppData.forceNoHwAcceleration() : v0;
        if ((v1) && !android.support.design.a.isTextEmpty(this.p) && (BaseAppData.inst().allowInsideDownloadManager())) {
            switch (this.L) {
                case 1: {
                    this.M = "feed_download_ad";
                    this.P = 2;
                    break;
                }
                case 2: {
                    this.M = "detail_download_ad";
                    this.P = 1;
                    break;
                }
                case 3: {
                    this.M = "comment_download_ad";
                    break;
                }
                case 4: {
                    this.M = "wap";
                    this.P = 4;
                    break;
                }
                case 5: {
                    this.M = "detail_download_ad";
                    this.P = 1;
                    break;
                }
            }

            this.mDownloadStatusBar.setVisibility(View.VISIBLE);
            this.b = new e$e();
            com.bytedance.common.utility.b.a.a(this.b, new String[]{this.p});
            try {
                if (!android.support.design.a.isTextEmpty(this.s)) {
                    this.t = new JSONObject();
                    this.t.put("log_extra", this.s);
                }

                MobAdClickCombiner.onAdEvent(this.mContext, this.M, "detail_show", Long.valueOf(this.r).longValue(), 0, this.t, this.P);
            } catch (Exception v0_2) {
                v0_2.printStackTrace();
            }
        } else {
            this.mDownloadStatusBar.setVisibility(View.GONE);
        }
        try {
            label_142:
            CookieManager.getInstance().setAcceptCookie(true);
        } catch (Throwable v0_3) {
        }

        this.mWebview.setDownloadListener(new m(this));
        SSWebSettings v1_1 = SSWebSettings.createWebSettings(this.getActivity());
        v0 = !v11 ? true : false;
        v1_1.hardwareAccelerate = v0;
        v1_1.setJavaScriptEnabled(this.mWebview);
        BaseAppData v0_4 = this.mBaseAppData;
        WebView v1_2 = this.mWebview;
        if (v1_2 != null) {
            v0_1 = v0_4.a(v1_2.getContext(), v1_2);
            if (!android.support.design.a.isTextEmpty(v0_1)) {
                v1_2.getSettings().setUserAgentString(v0_1);
            }
        }

        this.mWebview.setWebViewClient(new CustomWebViewClient(this));
        this.G = new CustomWebChromeClient(this);
        this.mWebview.setWebChromeClient(this.G);
        WebSettings v1_3 = this.mWebview.getSettings();
        int v0_5 = this.e ? WebSettings.LOAD_CACHE_ELSE_NETWORK : WebSettings.LOAD_DEFAULT;
        v1_3.setCacheMode(v0_5);
        this.y = v13;
        this.f();
        this.K = new WapStatHelper();
        v0 = this.H > 0 || !android.support.design.a.isTextEmpty(this.U) ? true : false;
        this.X = v0;
        v0_1 = android.support.design.a.isTextEmpty(v13) ? null : Uri.parse(v13).getQueryParameter("webview_track_key");
        if (android.support.design.a.isTextEmpty(v0_1)) {
            v0_1 = v10;
        }

        if (!android.support.design.a.isTextEmpty(v0_1)) {
            this.K.mWebViewTrackKey = v0_1;
        }

        if (this.W == null || this.W.length() <= 0) {
            TTUtils.a(this.y, this.mWebview, v12);
        } else {
            HashMap v0_6 = new HashMap();
            AppUtil.appendAdditionHttpHeaders(v0_6, null, this.W);
            TTUtils.webViewLoadUrl(this.y, this.mWebview, v0_6);
        }
    }

    public void onActivityResult(int arg2, int arg3, Intent arg4) {
        super.onActivityResult(arg2, arg3, arg4);
        if (this.G != null) {
            this.G.onActivityResult(arg2, arg3, arg4);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
        View view = layoutInflater.inflate(this.getLayoutId(), container, false);
        this.mSSHtmlProgressBar = view.findViewById(com.ss.android.article.browser.R.id.ss_htmlprogessbar);
        this.mWebview = this.getWebView(view);
        this.mWebview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        this.mFullscreenViewFrame = view.findViewById(com.ss.android.article.browser.R.id.customview_layout);
        this.mFullscreenViewFrame.setListener(new FullscreenVideoFrame.OnHideFullscreenVideoFrameListener() {
            public final void onHideFullscreenVideoFrame() {
                if (BrowserFragment.this.G != null) {
                    BrowserFragment.this.G.onHideCustomView();
                }
            }
        });
        this.mDownloadStatusBar = view.findViewById(com.ss.android.article.browser.R.id.download_status_bar);
        this.mDownloadStatusBar.setOnClickListener(new View.OnClickListener() {
            public final void onClick(View arg1) {
            }
        });
        this.mDownloadProgressBar = view.findViewById(com.ss.android.article.browser.R.id.download_progress);
        this.mDownloadStatusTv = view.findViewById(com.ss.android.article.browser.R.id.download_status);
        this.mDownloadStatusTv.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg13) {
                JSONObject v2;
                final JSONObject v1;
                String v0 = null;
                long v10 = 0;
                if (!BaseAppData.inst().allowInsideDownloadManager()) {
                    v1 = new JSONObject();
                    v2 = new JSONObject();
                    try {
                        v2.put("url", BrowserFragment.this.p);
                        if (BrowserFragment.this.mWebview != null) {
                            v0 = BrowserFragment.this.mWebview.getUrl();
                            v2.put("referer_url", v0);
                        }

                        if (!android.support.design.a.isTextEmpty(v0) && !v0.equals(BrowserFragment.this.y)) {
                            v2.put("init_url", BrowserFragment.this.y);
                        }

                        v2.put("ad_id", BrowserFragment.this.H);
                        v1.put("label", "browser");
                        v1.put("ext_json", v2);
                    } catch (JSONException v0_1) {
                    }

                    PermissionsManager.getInstance().requestPermissions(BrowserFragment.this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, new PermissionsResultAction() {

                        public final void onGranted() {
                            AppUtil.a(BrowserFragment.this.p, BrowserFragment.this.q, BrowserFragment.this.mContext, v1);
                        }

                        public final void onDenied(String arg1) {
                        }
                    });
                    return;
                }

                if (BrowserFragment.this.n == null) {
                    v1 = new JSONObject();
                    v2 = new JSONObject();
                    try {
                        v2.put("url", BrowserFragment.this.p);
                        if (BrowserFragment.this.mWebview != null) {
                            v0 = BrowserFragment.this.mWebview.getUrl();
                            v2.put("referer_url", v0);
                        }

                        if (!android.support.design.a.isTextEmpty(v0) && !v0.equals(BrowserFragment.this.y)) {
                            v2.put("init_url", BrowserFragment.this.y);
                        }

                        v2.put("ad_id", BrowserFragment.this.H);
                        v1.put("label", "browser");
                        v1.put("ext_json", v2);
                    } catch (JSONException v0_1) {
                    }

                    PermissionsManager.getInstance().requestPermissions(BrowserFragment.this,
                            new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"},
                            new PermissionsResultAction() {

                                public final void onGranted() {
                                    int v9 = 5;
                                    long v10 = 0;
                                    long v2 = AppUtil.a(BrowserFragment.this.p, BrowserFragment.this.q, BrowserFragment.this.mContext, v1);
                                    if (v2 >= v10) {
                                        SubscriptionRouter.c(new s(v2));
                                        DownloadAdapterProxy.inst()
                                                .registerDownloadListener(BrowserFragment.this.mContext,
                                                        Long.valueOf(v2),
                                                        BrowserFragment.this.o,
                                                        BrowserFragment.this.r,
                                                        BrowserFragment.this.L,
                                                        BrowserFragment.this.s);
                                        MobAdClickCombiner.onAdEvent(
                                                BrowserFragment.this.mContext,
                                                BrowserFragment.this.M,
                                                "click_start_detail",
                                                Long.parseLong(BrowserFragment.this.r),
                                                v10,
                                                BrowserFragment.this.t,
                                                v9);
                                    } else if (v2 < v10) {
                                        MobAdClickCombiner.onAdEvent(BrowserFragment.this.mContext,
                                                BrowserFragment.this.M,
                                                "download_failed_detail",
                                                Long.parseLong(BrowserFragment.this.r),
                                                v10,
                                                BrowserFragment.this.t, v9);
                                    }
                                }

                                public final void onDenied(String arg1) {
                                }
                            });
                    return;
                }

                DownloadAdapterProxy.inst().handleStatusClick(BrowserFragment.this.mContext, BrowserFragment.this.n.b, BrowserFragment.this.n.id, BrowserFragment.this.I);
                try {
                    switch (BrowserFragment.this.n.b) {
                        case 1:
                        case 2: {
                            MobClickCombiner.onEvent(BrowserFragment.this.mContext, BrowserFragment.this.M, "click_pause_detail", Long.parseLong(BrowserFragment.this.r), 0, BrowserFragment.this.t);
                            break;
                        }
                        case 4: {
                            MobClickCombiner.onEvent(BrowserFragment.this.mContext, BrowserFragment.this.M, "click_continue_detail", Long.parseLong(BrowserFragment.this.r), 0, BrowserFragment.this.t);
                            break;
                        }
                        case 8: {
                            if (ToolUtils.isAppInstalled(BrowserFragment.this.mContext, BrowserFragment.this.I)) {
                                MobClickCombiner.onEvent(BrowserFragment.this.mContext, BrowserFragment.this.M, "click_open_detail", Long.parseLong(BrowserFragment.this.r), 0, BrowserFragment.this.t);
                                break;
                            }

                            MobClickCombiner.onEvent(BrowserFragment.this.mContext, BrowserFragment.this.M, "click_install_detail", Long.parseLong(BrowserFragment.this.r), 0, BrowserFragment.this.t);
                            break;
                        }
                    }
                } catch (Exception v0_2) {
                    v0_2.printStackTrace();
                }

                if (BrowserFragment.this.n.id >= v10) {
                    SubscriptionRouter.c(new s(BrowserFragment.this.n.id));
                    DownloadAdapterProxy.inst().registerDownloadListener(BrowserFragment.this.mContext, Long.valueOf(BrowserFragment.this.n.id), BrowserFragment.this.o, BrowserFragment.this.r, BrowserFragment.this.L, BrowserFragment.this.s);
                }
            }
        });
        this.mDownloadStatusBar.setVisibility(View.GONE);
        return view;
    }

    public void onDestroy() {
        LargeImageLoader v4 = null;
        super.onDestroy();
        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.b();
            this.mLargeImageLoader = v4;
        }

        if (this.S != null) {
            this.S.a = true;
            this.S = null;
        }

        this.R = null;
        if (this.b != null && this.b.getStatus() != AsyncTask.Status.FINISHED) {
            this.b.cancel(true);
            this.b = null;
        }

        if (this.n != null) {
            DownloadAdapterProxy.inst().unregisterDownloadListener(this.mContext, Long.valueOf(this.n.id), this.o);
        }

        this.n = null;
        if ((this.X) && this.K != null) {
            this.K.reportJumpCount(this.getActivity(), this.H, this.s);
        }

        if (this.K != null) {
            this.K.reportJumpLinks(this.getActivity(), this.H, this.s);
        }

        if (this.mJsObject != null) {
            this.mJsObject.clearWebDownloadListeners();
            this.mJsObject.b();
        }

        WebViewTweaker.clearWebviewOnDestroy(this.mWebview);
    }

    public void onPause() {
        super.onPause();
        android.support.v4.app.FragmentActivity v3 = this.getActivity();
        if ((this.X) && this.K != null && v3 != null) {
            JSONObject v9 = null;
            try {
                v9 = !android.support.design.a.isTextEmpty(this.V) ? new JSONObject(this.V) : new JSONObject();
                v9.put("log_extra", this.s);
            } catch (Exception v2) {
            }

            long v4 = System.currentTimeMillis() - this.T;
            if (v4 > 3000) {
                WapStatHelper.a(((Context) v3), v4, this.H, this.U, v9);
            }

            if (!((Activity) v3).isFinishing()) {
//                goto label_50;
            } else {
                this.K.a(this.mWebview, new BaseArticle(0), this.H, this.U, v9);
            }
        }

//        label_50:
        WebViewPauseResumeCompat.onPause(this.mWebview);
        WebViewTweaker.tweakPauseIfFinishing(this.getActivity(), this.mWebview);
        if (this.mHandler != null && v3 != null && !((Activity) v3).isFinishing() && !this.mJsObject.a(this.y)) {
            this.mHandler.sendEmptyMessageDelayed(10011, 120000);
        }

        if (this.n != null && (BaseAppData.inst().allowInsideDownloadManager())) {
            DownloadAdapterProxy.inst().unregisterDownloadListener(this.mContext, Long.valueOf(this.n.id), this.o);
        }

        if (this.mJsObject != null) {
            JsObject.e();
        }
    }

    public void onResume() {
        if (this.mWebview != null) {
            this.mWebview.getSettings().setBlockNetworkLoads(false);
            if (this.mHandler != null) {
                this.mHandler.removeMessages(10011);
            }
        }

        this.T = System.currentTimeMillis();
        super.onResume();
        WebViewPauseResumeCompat.onResume(this.mWebview);
        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.a();
        }

        this.tryRefreshTheme();
        if (!android.support.design.a.isTextEmpty(this.p) && !android.support.design.a.isTextEmpty(this.r) && (BaseAppData.inst().allowInsideDownloadManager())) {
            if (this.b != null && this.b.getStatus() != AsyncTask.Status.FINISHED) {
                this.b.cancel(true);
                this.b = null;
            }

            this.b = new e$e();
            com.bytedance.common.utility.b.a.a(this.b, new String[]{this.p});
        }

        if (this.mJsObject != null) {
            this.mJsObject.onResume();
        }
    }

    public void onStop() {
        super.onStop();
        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.a.pause();
        }
    }

    static void p() {
    }

    public final boolean q() {
        boolean v0;
        if (this.mWebview == null || !this.mWebview.canGoBack()) {
            v0 = false;
        } else {
            this.mWebview.goBack();
            v0 = true;
        }

        return v0;
    }
}

